package com.dis.service.controller.admin;

import com.dis.common.annotation.CheckPermission;
import com.dis.pojo.queryDTO.ChronicDiseaseTypePageQueryDTO;
import com.dis.pojo.dto.ChronicDiseaseTypeDTO;
import com.dis.common.result.PageResult;
import com.dis.common.result.Result;
import com.dis.service.service.ChronicDiseaseTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/chronicDiseaseType")
@Api(tags = "慢性病种类管理")
@Slf4j
public class ChronicDiseaseTypeController {

    @Autowired
    private ChronicDiseaseTypeService chronicDiseaseTypeService;

    @PostMapping
    @ApiOperation("新增慢性病种类")
    @CheckPermission("disease:type:add")
    public Result save(@RequestBody ChronicDiseaseTypeDTO chronicDiseaseTypeDTO) {
        log.info("新增慢性病种类：{}", chronicDiseaseTypeDTO);
        chronicDiseaseTypeService.save(chronicDiseaseTypeDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("慢性病种类分页查询")
    @CheckPermission("disease:type:query")
    public Result<PageResult> page(ChronicDiseaseTypePageQueryDTO chronicDiseaseTypePageQueryDTO) {
        log.info("慢性病种类分页查询：{}", chronicDiseaseTypePageQueryDTO);
        PageResult pageResult = chronicDiseaseTypeService.pageQuery(chronicDiseaseTypePageQueryDTO);
        return Result.success(pageResult);
    }

    @PutMapping
    @ApiOperation("编辑慢性病种类")
    @CheckPermission("disease:type:edit")
    public Result edit(@RequestBody ChronicDiseaseTypeDTO chronicDiseaseTypeDTO) {
        log.info("编辑慢性病种类：{}", chronicDiseaseTypeDTO);
        chronicDiseaseTypeService.edit(chronicDiseaseTypeDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除慢性病种类")
    @CheckPermission("disease:type:delete")
    public Result delete(@PathVariable Integer id) {
        log.info("删除慢性病种类：{}", id);
        chronicDiseaseTypeService.delete(id);
        return Result.success();
    }
}
